import {messages} from "share/common";
import React from 'react';
import { connect } from 'react-redux';

import { Alert, Divider, Switch, InputNumber, Button, Form, message, Select, Checkbox, Radio, Row, Col } from 'antd';
const FormItem = Form.Item;
import 'styles/setting/form/form-detail.scss'
import menuRoute from "routes/menuRoute";
import formService from "../../form.service";

const Option = Select.Option;
const CheckboxGroup = Checkbox.Group;
const RadioGroup = Radio.Group;

class HuilianyiManagement extends React.Component{
  constructor(props){
    super(props);
    this.state = {
      saveLoading: false, //保存的loading
      disabled: true,
      isEditing: false,//是否点击编辑
      formManagement: menuRoute.getRouteItem('form-list', 'key'),//点击返回跳转到的页面
      travelPolicy: menuRoute.getRouteItem('expense-standard', 'key'),//点击差旅标准设置跳转到的页面
      travelApplypolicy: {},//差旅标准控制
      versionChange: {},//版本变更
      autoStop: {},//自动停用
      employeeAutoStop: {},//允许员工自动停用
      autoStopDays : {},//允许员工自动停用的天数
      employeeRestartUse: {},//允许员工重新启用
      employeeRestartDays: {},//允许员工重新启用的天数
      bookingPreference: {}, //机票统一订票方式
      bookingPreferenceHotel: {}, //酒店统一订票方式
      bookingPreferenceTrain: {}, //火车统一订票方式
      bookingPreferenceDining: {}, //用餐统一订票方式
      dateRangeEnable: {}, //控制出差日期范围
      hotelDuplicateEnable: {}, //控制酒店日期是否能重复
      autoBudget: {},//行程自动生成预算
      autoBudgetNotModify: {}, //自动生成的预算明细不可更改
      applicationShare: {}, //单据分享的配置
      itineraryTypes: [], //行程自动生成预算中的行程类型 flight train hotel allowance
      smartBooking: {}, //智能订票
      partialSubmit: {}, //余票不足是否部分提交
      advancePurchase: {}, //提前购买天数
      autoStopDaysDisabled: true,//允许员工自动停用的天数的inputNumber的disabled
      employeeRestartDaysDisabled: true,//允许员工重新启用的天数的inputNumber的disabled
      autoStopNumRequired: false,//允许员工自动停用的天数的inputNumber的表单的required
      restartNumRequired: false,//允许员工重新启用的天数的inputNumber的表单的required
      params: [],//提交时需要的参数
    }
    this.isMaLai = window.location.href.indexOf('console-my.huilianyi.com') !== -1 || window.location.href.indexOf('console-sg.huilianyi.com') !== -1; //是否是马来环境
  }
  componentWillMount() {
    const {propertyList} = this.props;
    const {params} = this.state;
    propertyList.map(item => {
      if(item.propertyName === 'ca.travel.applypolicy.enable') {
        this.setState({
          travelApplypolicy: item,
        })
      }
      if(item.propertyName === 'application.change.enable') {
        this.setState({
          versionChange: item,
        })
      }
      if(item.propertyName === 'application.close.enabled') {
        this.setState({
          autoStop: item,
        }, () => {
          this.setState({
            autoStopNumRequired: this.state.autoStop.propertyValue === '1' || this.state.autoStop.propertyValue === 1 ? true : false,
          })
        })
      }
      if(item.propertyName === 'application.close.closeDay') {
        this.setState({
          autoStopDays: item,
        })
      }
      if(item.propertyName === 'application.close.restart.closeDay') {
        this.setState({
          employeeRestartDays: item,
        })
      }
      if(item.propertyName === 'application.close.participant.enabled') {
        this.setState({
          employeeAutoStop: item,
        })
      }
      if(item.propertyName === 'application.close.restart.enabled') {
        this.setState({
          employeeRestartUse: item,
        }, () => {
          this.setState({
            restartNumRequired: this.state.employeeRestartUse.propertyValue === '1' || this.state.employeeRestartUse.propertyValue === 1 ? true : false,
          })
        })
      }
      if(item.propertyName === 'ca.travel.bookingpreference') {
        this.setState({
          bookingPreference: item
        });
      }
      if(item.propertyName === 'ca.travel.hotel.bookingpreference') {
        this.setState({
          bookingPreferenceHotel: item
        });
      }
      if(item.propertyName === 'ca.travel.train.bookingpreference') {
        this.setState({
          bookingPreferenceTrain: item
        });
      }
      if(item.propertyName === 'ca.travel.dining.bookingpreference') {
        this.setState({
          bookingPreferenceDining: item
        });
      }
      if(item.propertyName === 'application.control.daterange.enable') {
        this.setState({
          dateRangeEnable: item
        });
      }
      if(item.propertyName === 'hotel.repetition.control') {
        this.setState({
          hotelDuplicateEnable: item
        });
      }
      if(item.propertyName === 'itinerary.auto.budget2') {
        this.setState({
          autoBudget: item,
          itineraryTypes: item.propertyValue ? JSON.parse(item.propertyValue).itineraryTypes : []
        });
      }
      if(item.propertyName === 'auto.budget.detail.not.modify') {
        this.setState({
          autoBudgetNotModify: item
        });
      }
      if(item.propertyName === 'travel.auto.booking.enable') {
        this.setState({
          smartBooking: item
        });
      }
      if(item.propertyName === 'travel.auto.booking.part.enable') {
        this.setState({
          partialSubmit: item
        });
      }
      if(item.propertyName === 'travel.auto.booking.advance.days') {
        this.setState({
          advancePurchase: item
        });
      }
      if(item.propertyName === 'travel.application.share.image') {
        this.setState({
          applicationShare: item
        });
      }
    })
  }
  componentDidMount (){
    const { travelApplypolicy, versionChange, autoStop, employeeAutoStop, autoStopDays , employeeRestartUse,
      employeeRestartDays, bookingPreference, dateRangeEnable, autoBudget, smartBooking, partialSubmit, advancePurchase,
      hotelDuplicateEnable, applicationShare, autoBudgetNotModify, bookingPreferenceHotel, bookingPreferenceTrain,
      bookingPreferenceDining
    } = this.state;
    const {formOID} = this.props.params;
    if(!travelApplypolicy.hasOwnProperty('propertyName')){
      this.setState({
        travelApplypolicy:{
          formOID: formOID,
          propertyName: 'ca.travel.applypolicy.enable',
          propertyValue: null,
        }
      })
    }
    if(!versionChange.hasOwnProperty('propertyName')){
      this.setState({
        versionChange:{
          formOID: formOID,
          propertyName: 'application.change.enable',
          propertyValue: null,
        }
      })
    }
    if(!autoStop.hasOwnProperty('propertyName')){
      this.setState({
        autoStop:{
          formOID: formOID,
          propertyName: 'application.close.enabled',
          propertyValue: null,
        }
      })
    }
    if(!autoStopDays.hasOwnProperty('propertyName')){
      this.setState({
        autoStopDays:{
          formOID: formOID,
          propertyName: 'application.close.closeDay',
          propertyValue: null,
        }
      })
    }
    if(!employeeAutoStop.hasOwnProperty('propertyName')){
      this.setState({
        employeeAutoStop:{
          formOID: formOID,
          propertyName: 'application.close.participant.enabled',
          propertyValue: null,
        }
      })
    }
    if(!employeeRestartUse.hasOwnProperty('propertyName')){
      this.setState({
        employeeRestartUse:{
          formOID: formOID,
          propertyName: 'application.close.restart.enabled',
          propertyValue: null,
        }
      })
    }
    if(!employeeRestartDays.hasOwnProperty('propertyName')){
      this.setState({
        employeeRestartDays:{
          formOID: formOID,
          propertyName: 'application.close.restart.closeDay',
          propertyValue: null,
        }
      })
    }
    if(!bookingPreference.hasOwnProperty('propertyName')){
      this.setState({
        bookingPreference:{
          formOID: formOID,
          propertyName: 'ca.travel.bookingpreference',
          propertyValue: null,
        }
      })
    }
    if(!bookingPreferenceHotel.hasOwnProperty('propertyName')){
      this.setState({
        bookingPreferenceHotel:{
          formOID: formOID,
          propertyName: 'ca.travel.hotel.bookingpreference',
          propertyValue: null
        }
      });
    }
    if(!bookingPreferenceTrain.hasOwnProperty('propertyName')){
      this.setState({
        bookingPreferenceTrain:{
          formOID: formOID,
          propertyName: 'ca.travel.train.bookingpreference',
          propertyValue: null
        }
      });
    }
    if(!bookingPreferenceDining.hasOwnProperty('propertyName')){
      this.setState({
        bookingPreferenceDining:{
          formOID: formOID,
          propertyName: 'ca.travel.dining.bookingpreference',
          propertyValue: null
        }
      });
    }
    if(!dateRangeEnable.hasOwnProperty('propertyName')){
      this.setState({
        dateRangeEnable:{
          formOID: formOID,
          propertyName: 'application.control.daterange.enable',
          propertyValue: null
        }
      });
    }
    if(!hotelDuplicateEnable.hasOwnProperty('propertyName')){
      this.setState({
        hotelDuplicateEnable:{
          formOID: formOID,
          propertyName: 'hotel.repetition.control',
          propertyValue: null
        }
      });
    }
    if(!autoBudget.hasOwnProperty('propertyName')){
      this.setState({
        autoBudget:{
          formOID: formOID,
          propertyName: 'itinerary.auto.budget2',
          propertyValue: ""
        }
      });
    }
    if(!autoBudgetNotModify.hasOwnProperty('propertyName')){
      this.setState({
        autoBudgetNotModify: {
          formOID: formOID,
          propertyName: 'auto.budget.detail.not.modify',
          propertyValue: null
        }
      });
    }
    if(!smartBooking.hasOwnProperty('propertyName')){
      this.setState({
        smartBooking:{
          formOID: formOID,
          propertyName: 'travel.auto.booking.enable',
          propertyValue: null
        }
      });
    }
    if(!partialSubmit.hasOwnProperty('propertyName')){
      this.setState({
        partialSubmit:{
          formOID: formOID,
          propertyName: 'travel.auto.booking.part.enable',
          propertyValue: null
        }
      });
    }
    if(!advancePurchase.hasOwnProperty('propertyName')){
      this.setState({
        advancePurchase:{
          formOID: formOID,
          propertyName: 'travel.auto.booking.advance.days',
          propertyValue: null
        }
      });
    }
    if(!applicationShare.hasOwnProperty('propertyName')){
      this.setState({
        applicationShare:{
          formOID: formOID,
          propertyName: 'travel.application.share.image',
          propertyValue: null
        }
      });
    }
  }
  //处于编辑状态时切换tab相当于点击取消编辑
  componentWillReceiveProps(nextProps) {
    if(nextProps.params.activeKey !== this.props.params.activeKey){
      this.state.isEditing && this.cancelEditing();
    }
  }
  //点击编辑
  editClicked = () => {
    const {autoStop, employeeRestartUse} = this.state
    this.setState({
      isEditing: true,
      disabled: false,
    }, () => {
      if(autoStop.propertyValue === '1' || autoStop.propertyValue === 1 )
        this.setState({
          autoStopDaysDisabled: false,
        })
      if(employeeRestartUse.propertyValue === '1' || employeeRestartUse.propertyValue === 1){
        this.setState({
          employeeRestartDaysDisabled: false
        })
      }
    })
  }
  //取消编辑
  cancelEditing = () => {
    this.setState({
      isEditing: false,
      disabled: true,
      autoStopDaysDisabled: true,
      employeeRestartDaysDisabled: true
    }, () => {
      this.props.form.resetFields();
    })
  }
  //切换自动预算总开关
  handleChangeAutoBudget = (value) => {
    if (value) {
      this.setState({itineraryTypes: ['flight', 'train', 'hotel', 'allowance', 'airline', 'offlineHotel', 'urban', 'water']});
    }
  };
  //后面跟有inputNumber的两个switch按钮切换时
  onSwitchChange = (e, key) => {
    switch (key){
      case 'autoStop':this.setState({
        autoStopDaysDisabled: !e,
        autoStopNumRequired: e
      });
        break;
      case 'employeeRestartUse': this.setState({
        employeeRestartDaysDisabled: !e,
        restartNumRequired: e,
      })
        break;
    }
  }
//点击保存
  onFatherSaveClick = () => {
    const { travelApplypolicy, versionChange, autoStop, employeeAutoStop, autoStopDays , employeeRestartUse,
      employeeRestartDays, bookingPreference, autoStopNumRequired, restartNumRequired, dateRangeEnable, autoBudget,
      smartBooking, partialSubmit, advancePurchase, hotelDuplicateEnable, applicationShare, autoBudgetNotModify,
      bookingPreferenceHotel, bookingPreferenceTrain, bookingPreferenceDining
    } = this.state;
    this.props.form.validateFieldsAndScroll((err,values) => {
      if (!err) {
        travelApplypolicy.propertyValue = values.travelApplypolicy;
        versionChange.propertyValue = values.versionChange;
        autoStop.propertyValue = values.autoStop === true ? '1' : '0';
        employeeAutoStop.propertyValue = values.employeeAutoStop === true ? '1' : '0';
        autoStopDays.propertyValue = values.autoStopDays;
        employeeRestartUse.propertyValue = values.employeeRestartUse ===true ? '1' : '0';
        employeeRestartDays.propertyValue = values.employeeRestartDays;
        dateRangeEnable.propertyValue = values.dateRangeEnable;
        hotelDuplicateEnable.propertyValue = values.hotelDuplicateEnable;
        autoBudgetNotModify.propertyValue = values.autoBudgetNotModify;
        autoBudget.propertyValue = JSON.stringify({
          enabled: values.autoBudget,
          itineraryTypes: values.autoBudgetTypes
        });
        applicationShare.propertyValue = JSON.stringify({
          enabled: values.applicationShare,
          platform: [1001] //1001微信 1002企业微信 1003钉钉 这期先写死微信
        });
        if (values.autoBudget && !values.autoBudgetTypes.length) {
          message.error(messages('setting.key1854')/*请至少勾选一项行程预算*/);
          return;
        }
        //smartBooking.propertyValue = values.smartBooking;
        let params = [
          travelApplypolicy,
          versionChange,
          dateRangeEnable,
          hotelDuplicateEnable,
          //smartBooking,
          autoStop,
          applicationShare,
          employeeAutoStop,
          employeeRestartUse
        ];
        if (!this.isMaLai) {
          params.push(autoBudget);
          params.push(autoBudgetNotModify);
        }
        if (values.smartBooking) {
          partialSubmit.propertyValue = values.partialSubmit;
          params.push(partialSubmit);
          advancePurchase.propertyValue = values.advancePurchase;
          params.push(advancePurchase);
        }
        if (values.bookingPreference) {
          bookingPreference.propertyValue = values.bookingPreference;
          params.push(bookingPreference);
        }
        if (values.bookingPreferenceHotel) {
          bookingPreferenceHotel.propertyValue = values.bookingPreferenceHotel;
          params.push(bookingPreferenceHotel);
        }
        if (values.bookingPreferenceTrain) {
          bookingPreferenceTrain.propertyValue = values.bookingPreferenceTrain;
          params.push(bookingPreferenceTrain);
        }
        if (values.bookingPreferenceDining) {
          bookingPreferenceDining.propertyValue = values.bookingPreferenceDining;
          params.push(bookingPreferenceDining);
        }
        if(autoStopNumRequired && !parseInt(autoStopDays.propertyValue)){
          message.error(messages('setting.key1556')/*自动关闭天数必须为正整数*/);
          return;
        }
        if(restartNumRequired && !parseInt(employeeRestartDays.propertyValue)){
          message.error(messages('setting.key1557')/*重新启用的关闭天数必须为正整数*/);
          return;
        }
        if(autoStopNumRequired){
          params.push(autoStopDays);
        }
        if(restartNumRequired){
          params.push(employeeRestartDays);
        }
        this.setState({saveLoading: true});
        formService.saveHuilianyiForm(params).then(res => {
          if(res.status === 200){
            message.success(messages('setting.key211'/*保存成功*/))
            this.props.saveHandle(true)
          }else{
            message.error(messages('setting.key212'/*保存失败*/))
          }
          this.setState({
            saveLoading: false,
            disabled: true,
            isEditing: false,
            autoStopDaysDisabled: true,
            employeeRestartDaysDisabled: true
          })
        }).catch(e => {
          this.setState({saveLoading: false});
          let error = e.response.data;
          if (error.validationErrors && error.validationErrors.length) {
            message.error(`${messages('common.save.filed')}，${error.validationErrors[0].message}`);
          } else {
            message.error(`${messages('common.save.filed')}，${error.message}`);
          }
        });
      }
    });
  };
  render(){
    const { getFieldDecorator, getFieldValue } = this.props.form;
    const { formManagement, disabled, isEditing, travelApplypolicy, versionChange, autoStop, autoStopDays,
      employeeAutoStop, employeeRestartUse, autoStopDaysDisabled, employeeRestartDays, employeeRestartDaysDisabled,
      travelPolicy, autoStopNumRequired, restartNumRequired, bookingPreference, dateRangeEnable, autoBudget, smartBooking,
      partialSubmit, advancePurchase, hotelDuplicateEnable, itineraryTypes, applicationShare, autoBudgetNotModify,
      saveLoading, bookingPreferenceHotel, bookingPreferenceTrain, bookingPreferenceDining } = this.state;
    const { disabled: hiding } = this.props;
    const formItemLayout = {
      labelCol: {span: 2},
      wrapperCol: {span: 22},
    };
    return(
      <div className='form-setting-huilianyi'>
        <Form hideRequiredMark={true}>
        <div className='huilianyi-alert'>
          <Alert
            message={messages("common.help")/*帮助提示*/}
            description={messages('setting.key643'/*设置该单据是否启用相应的管控规则*/)}
            type="info"
            showIcon/>
        </div>
        <div className='huilianyi-global'>
          <div className='huilianyi-module'>
            <FormItem  label={messages('setting.key644'/*差旅控制标准*/)}>
              {getFieldDecorator('travelApplypolicy', {
                rules: [{
                  required: true,
                }],
                valuePropName: 'checked',
                initialValue: travelApplypolicy.propertyValue === 'true' || travelApplypolicy.propertyValue === true ? true : false
                })(
                <Switch disabled={disabled}/>
              )}
            </FormItem>
            <Divider dashed />
            <span className='huilianyi-note'>
              {messages('setting.key645'/*启用后，该单据在添加行程时将自动应用公司设置的差旅标准，包括机票舱等、折扣、酒店单价上限、火车座席等*/)}
            </span>
            <div>{messages('setting.key646'/*前往*/)}
              <a onClick={() => {this.context.router.push(travelPolicy.url);}}>{messages('setting.key647'/*差旅标准设置*/)}</a>
              {messages('setting.key648'/*进行规则设置*/)}
            </div>
          </div>
          <div className='huilianyi-module'>
            <FormItem  label={messages('setting.key649'/*版本变更管理*/)}>
              {getFieldDecorator('versionChange', {
                rules: [{
                  required: true,
                }],
                valuePropName: 'checked',
                initialValue: versionChange.propertyValue === 'true' || versionChange.propertyValue === true ? true : false
              })(
                <Switch  disabled={disabled} />
              )}
            </FormItem>
            <Divider dashed />
            <span className='huilianyi-note'>{messages('setting.key650'/*启用后，差旅申请单审批通过后，员工可以修改单据。*/)}</span>
          </div>
          <div className='huilianyi-module'>
            <div className='module-form-switch'>
            <FormItem  label={messages('setting.key651'/*自动关闭*/)}>
              {getFieldDecorator('autoStop', {
                rules: [{
                  required: true,
                }],
                valuePropName: 'checked',
                initialValue: autoStop.propertyValue === '1' || autoStop.propertyValue === 1 ? true : false
              })(
                <Switch disabled={disabled} onChange={(e) => this.onSwitchChange(e, 'autoStop')}/>
              )}
            </FormItem>
            </div>
              <div className='module-form-item'>
            <span className='module-form-message'>{messages('setting.key652'/*差旅结束后*/)}</span>
            <FormItem  >
              {getFieldDecorator('autoStopDays', {
                rules: [{
                  required: false,
                }],
                initialValue: autoStopDays.propertyValue
              })(
                <InputNumber size='small' min={0} max={999} precision={0} disabled={autoStopDaysDisabled} />
              )}
            </FormItem>
              <span className='module-form-message'>{messages('setting.key653'/*天后系统自动关闭*/)}</span>
            </div>
            <Divider dashed/>
            <span className='huilianyi-note'>{messages('setting.key654'/*启用后，差旅结束后，在设置天数内自动关闭。*/)}</span>
          </div>
          <div className='huilianyi-module'>
            <FormItem  label={messages('setting.key655'/*允许员工自行关闭*/)}>
              {getFieldDecorator('employeeAutoStop', {
                rules: [{
                  required: true,
                }],
                valuePropName: 'checked',
                initialValue: employeeAutoStop.propertyValue === '1' || employeeAutoStop.propertyValue === 1 ? true : false
              })(
                <Switch disabled={disabled}/>
              )}
            </FormItem>
            <Divider dashed />
            <span className='huilianyi-note'>
              {messages('setting.key656'/*启用后，差旅申请单审批通过后，申请单内出现关闭按钮，员工可自行关闭差旅申请单。*/)}
            </span>
          </div>
          <div className='huilianyi-module'>
            <div className='module-form-switch'>
              <FormItem  label={messages('setting.key657'/*允许员工重新启用*/)}>
                {getFieldDecorator('employeeRestartUse', {
                  rules: [{
                    required: true,
                  }],
                  valuePropName: 'checked',
                  initialValue: employeeRestartUse.propertyValue === '1' || employeeRestartUse.propertyValue === 1 ? true : false
                })(
                  <Switch disabled={disabled} onChange={(e, key) => this.onSwitchChange(e, 'employeeRestartUse')}/>
                )}
              </FormItem>
            </div>
            <div className='module-form-item'>
            <span className='module-form-message'>{messages('setting.key658'/*重新启用*/)}</span>
            <FormItem>
              {getFieldDecorator('employeeRestartDays', {
                rules: [{
                  required: false,
                }],
                initialValue: employeeRestartDays .propertyValue
              })(
                <InputNumber size='small' min={0} max={999} precision={0} disabled={employeeRestartDaysDisabled} />
              )}
            </FormItem>
            <span className='module-form-message'>{messages('setting.key659'/*天后系统自动关闭*/)}</span>
            </div>
            <Divider dashed />
            <span className='huilianyi-note'>
              {messages('setting.key660'/*启用后，当申请单关闭后，申请单内启用按钮，支持员工重新启用申请单。*/)}
            </span>
          </div>
          <div className='huilianyi-module label-left'>
            <FormItem  label={messages('setting.key661'/*订票方式*/)} />
            <Divider dashed />
            <span className='huilianyi-note'>{messages('setting.key664'/*为差旅申请设置订票方式默认值*/)}</span>
            <FormItem {...formItemLayout} label={messages('setting.key892')/*机票*/}>
              {getFieldDecorator('bookingPreference', {
                initialValue: bookingPreference.propertyValue
              })(
                <RadioGroup disabled={disabled}>
                  <Radio value="Consolidated">{messages('setting.key2224')/*优先统一预订*/}</Radio>
                  <Radio style={{marginLeft: 20}} value="Individual">{messages('setting.key2225')/*优先各自预订*/}</Radio>
                  <Radio style={{marginLeft: 20}} value="OnlyConsolidated">{messages('setting.key2226')/*固定统一预订*/}</Radio>
                  <Radio style={{marginLeft: 20}} value="OnlyIndividual">{messages('setting.key2227')/*固定各自预订*/}</Radio>
                </RadioGroup>
              )}
            </FormItem>
            <FormItem {...formItemLayout} label={messages('setting.key707')/*酒店*/}>
              {getFieldDecorator('bookingPreferenceHotel', {
                initialValue: bookingPreferenceHotel.propertyValue
              })(
                <RadioGroup disabled={disabled}>
                  <Radio value="Consolidated">{messages('setting.key2224')/*优先统一预订*/}</Radio>
                  <Radio style={{marginLeft: 20}} value="Individual">{messages('setting.key2225')/*优先各自预订*/}</Radio>
                  <Radio style={{marginLeft: 20}} value="OnlyConsolidated">{messages('setting.key2226')/*固定统一预订*/}</Radio>
                  <Radio style={{marginLeft: 20}} value="OnlyIndividual">{messages('setting.key2227')/*固定各自预订*/}</Radio>
                </RadioGroup>
              )}
            </FormItem>
            <FormItem {...formItemLayout} label={messages('setting.key717')/*火车*/}>
              {getFieldDecorator('bookingPreferenceTrain', {
                initialValue: bookingPreferenceTrain.propertyValue
              })(
                <RadioGroup disabled={disabled}>
                  <Radio value="Consolidated">{messages('setting.key2224')/*优先统一预订*/}</Radio>
                  <Radio style={{marginLeft: 20}} value="Individual">{messages('setting.key2225')/*优先各自预订*/}</Radio>
                  <Radio style={{marginLeft: 20}} value="OnlyConsolidated">{messages('setting.key2226')/*固定统一预订*/}</Radio>
                  <Radio style={{marginLeft: 20}} value="OnlyIndividual">{messages('setting.key2227')/*固定各自预订*/}</Radio>
                </RadioGroup>
              )}
            </FormItem>
            <FormItem {...formItemLayout} label={messages('setting.key2228')/*用餐*/}>
              {getFieldDecorator('bookingPreferenceDining', {
                initialValue: bookingPreferenceDining.propertyValue
              })(
                <RadioGroup disabled={disabled}>
                  <Radio value="Consolidated">{messages('setting.key2224')/*优先统一预订*/}</Radio>
                  <Radio style={{marginLeft: 20}} value="Individual">{messages('setting.key2225')/*优先各自预订*/}</Radio>
                  <Radio style={{marginLeft: 20}} value="OnlyConsolidated">{messages('setting.key2226')/*固定统一预订*/}</Radio>
                  <Radio style={{marginLeft: 20}} value="OnlyIndividual">{messages('setting.key2227')/*固定各自预订*/}</Radio>
                </RadioGroup>
              )}
            </FormItem>
            <FormItem {...formItemLayout} label={messages('setting.key2229')/*用车*/}>
              <RadioGroup disabled={disabled} value="OnlyIndividual">
                <Radio value="OnlyIndividual">{messages('setting.key2227')/*固定各自预订*/}</Radio>
              </RadioGroup>
            </FormItem>
          </div>
          <div className='huilianyi-module'>
            <FormItem  label={messages('setting.key665'/*控制出差日期范围*/)}>
              {getFieldDecorator('dateRangeEnable', {
                rules: [{
                  required: true,
                }],
                valuePropName: 'checked',
                initialValue: dateRangeEnable.propertyValue === 'true' || dateRangeEnable.propertyValue === true
              })(
                <Switch  disabled={disabled} />
              )}
            </FormItem>
            <Divider dashed />
            <span className='huilianyi-note'>{messages('setting.key666'/*启用后，仅允许修改后的申请单出差日期范围包含已保存的行程日期范围。*/)}</span>
          </div>
          {/*行程自动生成预算明细*/}
          {!this.isMaLai && (
            <div className='huilianyi-module'>
              <FormItem className='module-form-switch' label={messages('setting.key1689')/*行程自动生成预算明细*/}>
                {getFieldDecorator('autoBudget', {
                  rules: [{
                    required: true,
                  }],
                  valuePropName: 'checked',
                  initialValue: autoBudget.propertyValue ? JSON.parse(autoBudget.propertyValue).enabled : false
                })(
                  <Switch disabled={disabled} onChange={value => this.handleChangeAutoBudget(value)}/>
                )}
              </FormItem>
              {getFieldValue('autoBudget') && (
                <div className='module-form-item'>
                  <FormItem  >
                    {getFieldDecorator('autoBudgetTypes', {
                      rules: [{
                        required: false,
                      }],
                      initialValue: itineraryTypes
                    })(
                      <CheckboxGroup disabled={disabled}>
                        <Checkbox className="check-box-item" value="flight">{messages('setting.key1855')/*TMC机票*/}</Checkbox>
                        <Checkbox className="check-box-item" value="train">{messages('setting.key717')/*火车*/}</Checkbox>
                        <Checkbox className="check-box-item" value="hotel">{messages('mcd.tmc.hotel')/*TMC酒店*/}</Checkbox>
                        <Checkbox className="check-box-item" value="airline">{messages('mcd.cus.airline'/*非TMC机票*/)}</Checkbox>
                        <Checkbox className="check-box-item" value="offlineHotel">{messages('mcd.cus.hotel'/*非TMC酒店*/)}</Checkbox>
                        <Checkbox className="check-box-item" value="urban">{messages('mcd.cus.city.traffic'/*市内交通*/)}</Checkbox>
                        <Checkbox className="check-box-item" value="water">{messages('mcd.cus.amphibious'/*水陆客运*/)}</Checkbox>
                        <Checkbox className="check-box-item" value="allowance">{messages('setting.key1856')/*差补*/}</Checkbox>
                      </CheckboxGroup>
                    )}
                  </FormItem>
                </div>
              )}
              <Divider dashed />
              <span className='huilianyi-note'>{messages('setting.key1857')/*启用后，飞机、火车根据标准票价，酒店根据差旅标准金额，差补根据差补金额，自动生成预算明细。*/}</span>
            </div>
          )}
          {!this.isMaLai && getFieldValue('autoBudget') && (
            <div className='huilianyi-module'>
              <FormItem className='module-form-switch' label={messages('setting.key2049')/*自动生成的预算明细不可更改*/}>
                {getFieldDecorator('autoBudgetNotModify', {
                  rules: [{
                    required: true,
                  }],
                  valuePropName: 'checked',
                  initialValue: autoBudgetNotModify.propertyValue === 'true' || autoBudgetNotModify.propertyValue === true
                })(
                  <Switch disabled={disabled} />
                )}
              </FormItem>
              <Divider dashed />
              <span className='huilianyi-note'>{messages('setting.key2050')/*启用后，系统自动生成的预算明细不可更改。*/}</span>
            </div>
          )}
          { false && (
            <div className='huilianyi-module' style={this.props.form.getFieldValue('smartBooking') ? {marginBottom: 0} : null}>
              <FormItem  label={messages('setting.key1691')/*使用智能订票*/}>
                {getFieldDecorator('smartBooking', {
                  rules: [{
                    required: true,
                  }],
                  valuePropName: 'checked',
                  initialValue: smartBooking.propertyValue === 'true' || smartBooking.propertyValue === true
                })(
                  <Switch  disabled={disabled} />
                )}
              </FormItem>
              <Divider dashed />
              <span className='huilianyi-note'>{messages('setting.key1692')/*在申请单审批通过后，委托系统通过价格预测，在价格合适的时候自动下单订票，需先开通甄选机票。*/}</span>
            </div>
          )}
          { false && this.props.form.getFieldValue('smartBooking') && (
            <div className='huilianyi-module'>
              <FormItem  label={messages('setting.key1693')/*余票部分满足是否提交部分*/}>
                {getFieldDecorator('partialSubmit', {
                  rules: [{
                    required: true,
                  }],
                  valuePropName: 'checked',
                  initialValue: partialSubmit.propertyValue === 'true' || partialSubmit.propertyValue === true
                })(
                  <Switch disabled={disabled} />
                )}
              </FormItem>
              <FormItem label={messages('setting.key1694')/*提前购买天数*/}>
                {getFieldDecorator('advancePurchase', {
                  rules: [{
                    required: false,
                  }],
                  initialValue: advancePurchase.propertyValue ? advancePurchase.propertyValue : 2
                })(
                  <InputNumber size='small' min={1} max={7} precision={0} disabled={disabled} />
                )}
                <span style={{fontSize: 10}}>{messages('setting.key1695')/*备注：智能订票最晚不能超过航班起飞前的天数，到达期限直接购买*/}</span>
              </FormItem>
            </div>
          )}
          <div className='huilianyi-module'>
            <FormItem  label={messages('setting.key1858')/*酒店日期允许重复*/}>
              {getFieldDecorator('hotelDuplicateEnable', {
                rules: [{
                  required: true,
                }],
                valuePropName: 'checked',
                initialValue: hotelDuplicateEnable.propertyValue === 'true' || hotelDuplicateEnable.propertyValue === true
              })(
                <Switch  disabled={disabled} />
              )}
            </FormItem>
            <Divider dashed />
            <span className='huilianyi-note'>{messages('setting.key1859')/*启用后，不校验当前单据范围内重复日期的酒店行程。*/}</span>
          </div>
          <div className='huilianyi-module'>
            <FormItem  label={messages('setting.key1890')/*允许转发*/}>
              {getFieldDecorator('applicationShare', {
                rules: [{
                  required: true,
                }],
                valuePropName: 'checked',
                initialValue: applicationShare.propertyValue ? JSON.parse(applicationShare.propertyValue).enabled : false
              })(
                <Switch  disabled={disabled} />
              )}
            </FormItem>
            <Divider dashed />
            <span className='huilianyi-note'>{messages('setting.key1891')/*单据被提交后，允许提交人转发至社交软件进行审批或查看*/}</span>
          </div>
        </div>
        {!hiding && (
          <div className='form-setting-buttons bottom-bar'>
            {isEditing ?
              <div>
                <Button type='primary' className='buttons-save' loading={saveLoading} onClick={this.onFatherSaveClick}>
                  {messages("common.save")/*保存*/}
                </Button>
                <Button type='primary' className='buttons-cancelEdit' onClick={this.cancelEditing}>
                  {messages('setting.key667'/*取消编辑*/)}
                </Button>
                <Button type='default' onClick={() => {
                  this.context.router.replace(formManagement.url);
                }}>{messages("common.back")/*返回*/}</Button>
              </div>
              :
              <div>
                <Button type='primary' className='buttons-edit' onClick={this.editClicked}>{messages("common.edit")/*编辑*/}</Button>
                <Button type='default' onClick={() => {
                  this.context.router.replace(formManagement.url);
                }}>{messages("common.back")/*返回*/}</Button>
              </div>
            }
          </div>
        )}
        </Form>
      </div>
    )
  }
}
HuilianyiManagement.contextTypes = {
  router: React.PropTypes.object
};
function mapStateToProps(state) {
  return {}
}
const wrappedNewContract = Form.create()(HuilianyiManagement);
export default connect(mapStateToProps)(wrappedNewContract);

